using System;
using System.Collections.Generic;
using System.Text;
using AF_ORM.CORE;
using System.Data;
using System.Data.SqlClient;
namespace Bussiness.Manager
{
                

    public class PT_ToolInBillManager:Bussiness.ManagerBase.PT_ToolInBillManagerBase
    {
            public static PT_ToolInBillManager CreateInstant()
            {
                return new PT_ToolInBillManager();
            }
            public int DeleteByBillNo_And_ToolType(string BillNo, int ToolType)
            {
                string sql = "DELETE FROM PT_ToolInBill WHERE BillNo=@BillNo AND ToolType=@ToolType";
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@BillNo", BillNo);
                param[1] = new SqlParameter("@ToolType", ToolType);
                return SqlHelper.ExecuteNonQuery(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql, param);
            }

            public DataTable SelectByBillNoAndToolType(string BillNo, int ToolType)
            {
                string sql = @"Select 
                               Row_Number() OVER (ORDER BY Part_No) AS STT,
                               BillNo,
                               Part_Name,
                               Part_No,
                               QTY,
                               Price_After_Discount as Price,
                               Amount
                               FROM PT_ToolInBill WHERE BillNo=@BillNo AND ToolType=@ToolType";
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@BillNo", BillNo);
                param[1] = new SqlParameter("@ToolType", ToolType);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql, param);
            }
            public DataTable ViewSynchroData(DateTime date)
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@date", date);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "spLayPhuTungMangVe", param);
            }
            public string SynchroData(DateTime date,string createdby)
            {
                SqlParameter[] param = new SqlParameter[3];
                param[0] = new SqlParameter("@date", date);
                param[1] = new SqlParameter("@createdBy", createdby);
                param[2] = new SqlParameter("@message", "");
                param[2].Size = 1000;
                param[2].Direction = ParameterDirection.Output;
                
                SqlHelper.ExecuteNonQuery(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "spImportPhuTungMangVe", param);
                return param[2].Value.ToString();
            }
          
    }
}
                    
